package com.mcmaster.android.control;

import java.io.FileNotFoundException;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.mcmaster.android.MapOverlay;
import com.mcmaster.android.Output;
import com.mcmaster.android.data.Building;
import com.mcmaster.android.data.BuildingDatabase;
import com.mcmaster.android.control.QRControl;

public class FreeExploreControl implements QRControl, Controller {
	// Members
	private Activity ui_;
	private MapController mc_;
	private MapView mv_;
	private List<Overlay> list_overlays_;
	
	public FreeExploreControl(Activity u, MapView mv) {
		ui_ = u;
		mc_ = mv.getController();
		mv_ = mv;
		list_overlays_ = mv.getOverlays();
	}

	public void startQRReader(String content) {
		//String temp_qrcode 			= "f7f34f9f2jf92fk9f2f2f2f29fjk290fj";
		Building scanned_building_ 	= BuildingDatabase.getBuildingFromQR(content);
		String bld_name 			= scanned_building_.getName();
		String bld_description 		= scanned_building_.getDescription();
		GeoPoint point_ = scanned_building_.getLocation();
		
		mc_.setZoom(19);
		addPointOverlay(point_);
		
		Intent i = new Intent(ui_, Output.class);
		i.putExtra("name", bld_name);
		i.putExtra("descrip", bld_description);
		ui_.startActivity(i);
		
	}
	
	private void addPointOverlay(GeoPoint point) {
		mc_.animateTo(point);
		MapOverlay mo_ = new MapOverlay(point);
		list_overlays_.add(mo_);
		mv_.invalidate();
	}

	@Override
	public void openBuildingInfo(Building b) {
		// TODO Auto-generated method stub
		
	}
	
}
